<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var arr = [1, 2, 43];
    var json = { a: 6, b: 4, c: [1, 2, 3] };
    var str = 'sdfsdf';

    var json2 = clone(json);

    alert(json['c'])
    json2['c'] = [1,2]
    console.log(json2);
    console.log(json);
    function clone(obj) {
      var oNew = new obj.constructor(obj.valueOf());
      if (obj.constructor == Object) {
        for (var i in obj) {
          oNew[i] = obj[i];
          if (typeof (oNew[i]) == 'object') {
            clone(oNew[i]);
          }
        }
      }
      return oNew;
    }

    //判断变量是否是String类型
  //   typeof(obj) == 'string'
  //   obj.constructor == 'String'
  </script>
</body>

</html>